package com.test.test01.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.test.test01.common.request.bo.BannerBo;
import com.test.test01.bean.Banner;
import com.test.test01.serviceImpl.BannerServiceImpl;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
public class BannerController {


    @Resource
    private BannerServiceImpl bannerService;

    @GetMapping(value = "testBanner")
    public Object testBanner(@Valid @RequestBody BannerBo bo) {
        Banner one = bannerService.getOne(Wrappers.lambdaQuery(Banner.class)
                .eq(!StringUtils.isEmpty(bo.getName()), Banner::getType, bo.getName()).eq(Banner::getImageUrl, bo.getUrl()));
        return one;
    }

    @GetMapping(value = "addBanner")
    public boolean addBanner(Banner bo) {
        int i = bannerService.saveBanner(bo);
        System.out.println(i);
        return true;
    }

    @GetMapping(value = "listBanner")
    public List<Banner> addBanner() {
        List<Banner> banners = bannerService.listBanner();

        return banners;
    }

}

